/**
* Company: QuantaNetwork BeiJing Ltd
* Author : 张彦龙
* DateTime: Nov 26, 2008  8:16:39 PM
*/
package com.quantanetwork.esm.port;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class IdentifyDefault extends IdentifyMethod
{
	@Override
	public Portinfo indentify(String server, int port, String message, String type, int timeOut)
	{
		Portinfo bean = null;
		try
		{
			bean = new Portinfo();
			String portInfo = "";
			File file = new File("etc/services.lst");
			synchronized (file)
			{
				FileInputStream fileInputStream = new FileInputStream(file);
				BufferedReader br = new BufferedReader(new InputStreamReader(fileInputStream));
				String line = null;
				boolean flag = false;
				while ((line = br.readLine()) != null)
				{
					if (line.indexOf(port + "/tcp") > 0)
					{
						flag = true;
						break;
					}
				}
				fileInputStream.close();
				if (flag)
				{
					if (!line.substring(10, 34).trim().equals(""))
					{
						portInfo += "可能端口名称:" + line.substring(10, 34).trim();
					}
					if (!line.substring(34).trim().equals(""))
					{
						portInfo += "描述:" + line.substring(34).trim();
					}
				}
			}
			bean.setAdvice(portInfo);
		}
		catch (Exception e)
		{
			logger.info(e.getMessage());
		}
		return bean;
	}
}
